package lx;

import java.io.*;
import java.util.*;

/*
       需求：把《出师表》的文章顺序进行恢复到一个新文件中。
  */
public class demo2Case2 {
    public static void main(String[] args) throws IOException {
        //1.读取数据
        BufferedReader br = new BufferedReader(new FileReader("a.txt"));


        ArrayList<String> list = new ArrayList<>();
        String s;
        while ((s = br.readLine()) != null) {
            list.add(s);

        }
        //排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i1=Integer.parseInt(o1.split("\\.")[0]);
                int i2=Integer.parseInt(o2.split("\\.")[0]);
                return i1-i2;
            }
        });
        br.close();
        //3.写出数据
        BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt"));
        for (String t :list) {
            bw.write(t);
            bw.newLine();
        }
        bw.close();



    }
}
